package com.itheima;

import java.io.*;
import java.nio.file.*;

public class FilePaste {
    public static void pasteFile(String CopyPath,String destination) throws IOException
    {
        Path source = Paths.get(CopyPath);
        Path dest = Paths.get(destination);
        if(Files.isDirectory(source))
        {
            copyDirectory(source,dest);

        }
        else
        {
            Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
        }


    }
    public static void copyDirectory(Path source,Path dest)throws IOException
    {
        Files.createDirectories(dest);
        try(DirectoryStream<Path> stream = Files.newDirectoryStream(source))
        {
            for(Path entry : stream)
            {
                Path target_path = dest.resolve(entry.getFileName());
                if(Files.isDirectory(entry))
                {
                    copyDirectory(entry,target_path);
                }
                else
                {
                    Files.copy(entry, target_path, StandardCopyOption.REPLACE_EXISTING);
                }
            }
        }
    }
}
